package bancosys.tec.services.implementor.execution;

import jmine.tec.di.metadata.DependencyMetaData;
import jmine.tec.di.scope.TypedScope;
import jmine.tec.utils.reflection.fast.FastMethod;
import bancosys.tec.services.implementor.descriptor.ServiceExecutionProxy;

/**
 * Responsável pela execucao do servico propriamente dito. Resolve parâmetros dependentes se necessário.
 */
public class ServiceExecutionProxyImpl extends AbstractServiceExecutionProxy implements ServiceExecutionProxy {

    private final FastMethod executionMethod;

    /**
     * @param executionMethod o metodo que executa
     * @param resolvers os descritores de parametros do metodo de execucao.
     */
    public ServiceExecutionProxyImpl(FastMethod executionMethod, DependencyMetaData[] resolvers) {
        super(resolvers, extractOutName(executionMethod.getMethod()), isLiteral(executionMethod.getMethod()));
        this.executionMethod = executionMethod;
    }

    /**
     * @param target object
     * @param properties scope
     * @throws Exception e
     * @return Object
     */
    public Object hydrateAndExecute(Object target, TypedScope properties) throws Exception {
        return this.executionMethod.invoke(target, this.resolveObjects(properties));
    }

}
